package com.jfinal.demo.web.controller;

import java.io.File;

import com.jfinal.core.Controller;
import com.jfinal.demo.config.AppConfig;
import com.jfinal.demo.config.common.Constants;
import com.jfinal.demo.config.common.MyFile;
import com.jfinal.demo.web.render.ImageFileRender;
import com.jfinal.render.FileRender;

/**
 * 处理文件文件下载
 * 
 * @author Administrator
 * 
 */
public class FileController extends Controller {

	/**
	 * 文件下载
	 */
	public void download() {
		String filePath = getPara("filePath");
		render(new FileRender(getFileByFilePath(filePath)));
	}

	/**
	 * 图片展示
	 */
	public void show() {
		String filePath = getPara("filePath");
		File file = new File(AppConfig.get(Constants.KEY_FILE_SAVE_PATH)
				+ filePath);
		render(new ImageFileRender(file));
	}

	private File getFileByFilePath(String filePath) {
		File file = new MyFile(AppConfig.get(Constants.KEY_FILE_SAVE_PATH)
				+ filePath);
		return file;
	}
}
